#include "OGLRenderDevice.h"
#include "OGLRenderContext.h"
#include "EglWrapper.h"
#include "OGLDefs.h"

OGLRenderDevice::OGLRenderDevice(const RenderSetup& setup) {
	EglSetup eglSetup;
	eglSetup.RedBits = 8;
	eglSetup.GreenBits = 8;
	eglSetup.BlueBits = 8;
	eglSetup.AlphaBits = 8;
	eglSetup.DepthBits = 24;
	eglSetup.StencilBits = 8;

	m_egl = CreateEglWrapper(eglSetup, setup.Window);
	EGL_CONTEXT context = m_egl->CreateContext();
	m_egl->MakeCurrent(context);

	m_renderContext = make_shared<OGLRenderContext>();
}

OGLRenderDevice::~OGLRenderDevice() {
	m_egl->DeleteContext(m_egl->GetCurrentContext());
}

IEngineRenderContextPtr OGLRenderDevice::GetRenderContext() const {
	return m_renderContext;
}

void OGLRenderDevice::Present() {
	m_egl->Present();
}